package com.sun.service;

import com.sun.mapper.EmployeeMapper;
import com.sun.pojo.Employee;
import org.apache.ibatis.session.RowBounds;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author shkstart
 * @create 2021-08-08 21:59
 */
@Service
public class EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    public Employee getOne(Employee employee){
        return employeeMapper.selectOne(employee);
    }
    public List<Employee> getSelect(Employee employee) {
        //根据实体中的属性值进行查询，查询条件使用等号
        return employeeMapper.select(employee);
    }
    public List<Employee> getSelectAll() {
        //查询全部结果，select(null)方法能达到同样的效果
        return employeeMapper.selectAll();
    }
    public int getSelectCount(Employee employee) {
        //根据实体中的属性查询总数，查询条件使用等号
        return employeeMapper.selectCount(employee);
    }
    public Employee getSelectByPrimaryKey(Integer empId){
        //根据主键字段进行查询，方法参数必须包含完整的主键属性，查询条件使用等号
        return  employeeMapper.selectByPrimaryKey(empId);
    }
    public boolean isExists(Integer empId){
        return employeeMapper.existsWithPrimaryKey(empId);
    }
    public int saveEmployee(Employee employee){
        //保存一个实体，null的属性也会保存，不会使用数据库默认值
        return employeeMapper.insert(employee);

    }
    public int saveEmployeeSelective(Employee employee){
        //保存一个实体，null的属性不会保存，会使用数据库默认值
        return employeeMapper.insertSelective(employee);
    }
    public void updateEmployee(Employee employee){
        //根据主键更新实体全部字段，null值会被更新
        employeeMapper.updateByPrimaryKey(employee);
    }
    public void updateEmployeeSelective(Employee employee){
        //根据主键更新属性不为null的值
        employeeMapper.updateByPrimaryKeySelective(employee);
    }
    public void removeEmployee(Employee employee){
        //根据实体属性作为条件进行删除，查询条件使用等号
        employeeMapper.delete(employee);
    }
    public void removeEmployeeById(Integer empId){
        //根据主键字段进行删除，方法参数必须包含完整的主键属性
        employeeMapper.deleteByPrimaryKey(empId);
    }
    public List<Employee> getEmployeeByExample(Example example){
        //根据Example条件进行查询
        return employeeMapper.selectByExample(example);
    }
    public List<Employee> getEmpListByRowBounds(RowBounds rowBounds) {
        return employeeMapper.selectByRowBounds(null, rowBounds);
    }
    public int getSelectCountByExample(Example example){
        return employeeMapper.selectCountByExample(example);
    }
}
